<?php

namespace Database\Seeders;

use App\Models\User;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;

class FansSeeder extends Seeder
{
    /**
     * Run the database seeds.
     */
    public function run()
    {
        $users = User::all();
        $user = User::first();
        $user_id = $user->id;

        //提取除一号用户之外用户的所有人
        $fans = $users->slice(1);
        //提取1号用户之外的所有用户的id为数组
        $fans_id = $fans->pluck('id')->toArray();

        //1号用户关注除自己以外的所有人
        $user->fan($fans_id);

        //除1号用户之外的所有人都关注了1号用户
        foreach ($fans as $fan) {
            $fan->fan($user_id);
        }

    }
}
